package com.studymaster.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.json.MappingJacksonJsonView;

import com.studymaster.service.UserService;


@Controller
public class UserConstroller {
     
	@Autowired
	private UserService userService;
	
	@RequestMapping(value = "/updateuserkey.do" , method = RequestMethod.GET)
	public ModelAndView updateUserPassword(@RequestParam("studentid") String studentid,
			@RequestParam("password") String password,@RequestParam("newpassword") String newpassword
			,HttpServletRequest request, ModelMap model) {
		
		boolean isSuccess = userService.updateUserPassword(studentid, password, newpassword);
		if(isSuccess){  //密码修改成功
			model.put("errorcode", "1");
		}else{//密码修改不成功
			model.put("errorcode", "2");
		}
		
		return new ModelAndView(new MappingJacksonJsonView(), model);
		
	}
}
